﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace Umbrella.Whs.Service.Activities.SharePoint
{

    public sealed class UninstallMsiPackage : SafeCodeActivity
    {
        [RequiredArgument]
        public InArgument<Guid> ProductId { get; set; }

        public InArgument<string> Parameters { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void ExecuteSafe(CodeActivityContext context)
        {
            var id = context.GetValue(this.ProductId);
            var p = context.GetValue(this.Parameters);

            // build command line arguments
            var cmd = new StringBuilder();

            cmd.Append("/qb /norestart /x ");
            cmd.Append(id.ToString("B"));

            if (!string.IsNullOrEmpty(p))
            {
                cmd.Append(" ");
                cmd.Append(p);
            }

            // run
            var rp = new RunProcessLogged(
                "msiexec",
                cmd.ToString(),
                null
                );

            rp.Run();
        }
    }
}
